<?php

/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
*/

class Email extends CI_Controller {

	function index() {
		//echo ' Hello World';
		//$this->load->view("email_form");
	}
	/**
	 * send email
	 */
	function sendemail() {
		$this->load->helper('aws_email');
		send_email_via_ses('alokdixit.pss@gmail.com', 'registration@gworldtraveler.com', 'gWorldtraveler.com Account Activation', 'Please click the following link to activate <br />' . site_url() . '/email/accountactivation/emailAddress/pwintphyushwe@gmail.com/code/' . 1234);
	}
	
	/**
	 * account activation
	 * @param unknown_type $emailParam
	 * @param unknown_type $emailAddress
	 * @param unknown_type $actParam
	 * @param unknown_type $code
	 */
	function accountactivation($emailParam, $emailAddress, $actParam, $code) {


		$actiuser = array();
		$actiuser['emailAddress'] = $emailAddress;
		$actiuser['activationCode'] = $code;

		$this->load->model('Profile_model');
		$result = $this->Profile_model->activate_user($actiuser);
		$data['title'] = 'Account activation';
		if($result == 1){
				
			$data['message'] = 'Yor account has been already activated!. click '.anchor(site_url('login'), 'here').' to login';
		}
		else if($result && $result !=1) {
				
			$data ['message'] = 'Congradulations '.$result[0]['firstName'].' '.$result[0]['lastName'].'! Your account has been activate. Click '.anchor(site_url('login'), 'here').' to login </div>';
				
				
		} else {

			//echo "Please try again later.";
			$data['message'] =  'The link is incorrect. Please verify your mail and enter the correct link. If are still not able to activate your account, then click '.anchor(site_url('login/reSendEmail/'.$emailAddress), 'here').' to resend the activation code';
		}

		// load view
		$this->load->view('successful', $data);
	}
	
	/*
	 * resend email
	 */
	function reSendEmail($emailId) {
		$this->load->model('account_model');
		$result = $this->account_model->get_activationbyemailid($emailId);
		// echo $result;
		if ($result == 1) {
			$hdata['pageTitle'] = 'Login';
			$this->load->view('/includes/header', $hdata);
			$pagedata['notice'] = 'The account has been already activated !.';
			$this->load->view('forms/login', $pagedata);
			$this->load->view('/includes/footer');
		} else if ($result) {
			$this->load->helper('aws_email');
			send_email_via_aws($messagePrarm);
			
		} else {
			$hdata['pageTitle'] = 'Login';
			$this->load->view('/includes/header', $hdata);
			$pagedata['notice'] = 'The link is incorrect. Please verify your mail and enter the correct link. If are still not able to activate your account, then click ' . anchor(site_url('login/reSendEmail/' . $emailId), 'here') . ' to resend the activation code';
			$this->load->view('forms/login', $pagedata);
			$this->load->view('/includes/footer');
		}
	}
	/**
	 * [contactus description]
	 * This function is called by Contact Us Form
	 * @return [type] [description]
	 */
	function contactus(){
		if ($this->input->post('phone_number'))
				$phone_number = $this->input->post('phone_number');

		$email = $this->input->post('email');
		$name = $this->input->post('name');
		$body = $this->input->post('message');
		$message = '<br /><p> Name: '. $name .'</p>'
			        			. '<p> Phone Number: '.$phone_number .'</p>'
			        			. '<p> Email: ' . $email . '</p>'
			        			. $body;
			         $messageParam['to'] =  'info@maykhaclassifieds.com';
					 $messageParam['from'] = $this->config->item('email');
					 $messageParam['subject'] = '[Maykhaclassified.com]: Enquiry';
					 $messageParam['messagebody'] = $message;
					 $messageParam['replyTo'] = trim($email);
					 $messageParam['url'] = 'www.maykhaclassifieds.com';
	     $this->load->helper('aws_email');
	     send_email_via_aws($messageParam);
		$data['header'] = 'Thank you for sending message to Maykha!';
		$data['currenturl'] = 'Contact us';
		$data['description'] = 'Our team will get back to you within 48 hours';
		$this->load->view('/pages/success', $data);
	}
}
?>
